package lab.gene.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import lab.gene.service.impl.GeneServiceImpl;


import com.opensymphony.xwork2.ActionSupport;

public class UpdateGeneCommentAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
	
	private static final long serialVersionUID = 1L;
	private String geneName = null;
	private String comment = null;
	
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	} 

	
	public String execute() {
		System.out.println("Gene Comment Update Action!");
		System.out.println(comment);
		System.out.println("gene name:"+geneName);
		if (geneName != null) {

			Cookie[] cookies = servletRequest.getCookies();
			String cookieName = "LabUser";
			String username = null;
			if (cookies != null) {
				for (int i = 0; i < cookies.length; i++) {
					if (cookies[i].getName().equals(cookieName)) {
						username = cookies[i].getValue();
						break;
					}
				}
			}
			
			GeneServiceImpl service = new GeneServiceImpl();
			service.updateGeneComments(geneName, username, comment);
			
		}
		return "success";
	}
	
	public String getGeneName() {
		return geneName;
	}

	public void setGeneName(String geneName) {
		this.geneName = geneName;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}



}
